diff options
Diffstat (limited to 'src/routes/(app)/fund/[id]/+layout.server.ts')
| -rw-r--r-- | src/routes/(app)/fund/[id]/+layout.server.ts | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/routes/(app)/fund/[id]/+layout.server.ts b/src/routes/(app)/fund/[id]/+layout.server.ts index 3669eb7d..fb78b771 100644 --- a/src/routes/(app)/fund/[id]/+layout.server.ts +++ b/src/routes/(app)/fund/[id]/+layout.server.ts @@ -1,12 +1,24 @@ import getRates from "$lib/rates"; -import { get } from "$lib/utils"; +import { auth, get } from "$lib/utils"; -export const load = async ({ depends, params: { id }, parent }) => { +// Funds are discontinued: the page is a read-only view of a fund's history. +// Fetch with the viewer's token so a manager opening a pre-rotation link is +// served the rotated fund, and fall back to a "discontinued" notice instead of +// the generic error page when the fund can't be shown. +export const load = async ({ cookies, depends, params: { id }, parent }) => { depends("app:payments"); - const data = await get(`/fund/${id}`); - data.managers = await get(`/fund/${id}/managers`); - const rates = await getRates(); const { user } = await parent(); + const headers = user ? auth(cookies) : {}; + + let data; + try { + data = await get(`/fund/${id}`, headers); + data.managers = await get(`/fund/${data.id || id}/managers`); + } catch (e) { + data = { notFound: true, amount: 0, payments: [], managers: [] }; + } + + const rates = await getRates(); data.rate = rates[user?.currency || "USD"]; return data; }; |
